package com.example.wechat.csdnandroid.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.wechat.csdnandroid.R;
import com.example.wechat.csdnandroid.activity.ListView2Activity;
import com.example.wechat.csdnandroid.bean.Fruit;

import java.util.ArrayList;

public class FruitAdapter extends BaseAdapter {
    private ArrayList<Fruit> fruits;
    private Activity activity;
    private ImageView iv;
    private TextView tv;

    @Override
    public int getCount() {
        return fruits == null ? 0 : fruits.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //构造一个布局。左边是图片。右边是文字
        View view = LayoutInflater.from(activity).inflate(R.layout.item_listview_pic_text, parent, false);
        iv = (ImageView) view.findViewById(R.id.iv_ilpt);
        tv = (TextView) view.findViewById(R.id.tv_ilpt);
        Fruit fruit = fruits.get(position);
        iv.setImageResource(fruit.getPicImageRes());
        tv.setText(fruit.getPicText());
        return view;
    }


    public void setData(ArrayList<Fruit> data, ListView2Activity listView2Activity) {
        fruits = data;
        this.activity = listView2Activity;
    }
}
